#include <iostream>
using std::cout;
using std::endl;

class Singleton
{
    class AutoRelease{
    public:
        AutoRelease()
        {
            cout << "AutoRelease()" << endl;
        }

        ~AutoRelease(){
            if(_pInstance){
                delete _pInstance;
                _pInstance = nullptr;
            }
        }
    };
public:
    static Singleton* getInstance(){
        if(_pInstance == nullptr){
            _pInstance = new Singleton(1,2);
        }
        cout << "Singleton* getInstance()"<< endl;
        return _pInstance;
    }

    void init(int x,int y){
        _ix = x;
        _iy = y;
    }

    void print(){
        cout << "(" << this->_ix
            << "," << this->_iy
            << ")" << endl;
    }

private:
    Singleton() = default;

    Singleton(int x,int y)
        :_ix(x)
         ,_iy(y)
    {
        cout << "Singleton(int,int)" << endl;
    }

    ~Singleton(){
        cout << "~Singleton()" << endl;
    }

    Singleton(const Singleton & rhs) = delete;
    Singleton &operator=(const Singleton & rhs) = delete;

private:
    int _ix;
    int _iy;
    static Singleton* _pInstance;
    static AutoRelease _ar;
};

Singleton* Singleton::_pInstance = nullptr;
Singleton::AutoRelease Singleton::_ar;

void test0(){
    Singleton::getInstance()->init(10,20);
    Singleton::getInstance()->print();

}

int main(int argc, char * argv[])
{
    test0();
    return 0;
}


